<?php

/**
 * This is the model class for table "hs_user".
 *
 * The followings are the available columns in table 'hs_user':
 * @property integer $id
 * @property string $user_name
 * @property string $password
 * @property string $name
 * @property integer $gender
 * @property string $mobile
 * @property string $email
 * @property string $id_card
 * @property string $address
 * @property string $postcode
 * @property string $balance
 *
 * The followings are the available model relations:
 * @property Order $order
 */
class User extends CActiveRecord
{
	private $_identity;
	public $password2;
	public $verifyCode;
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'hs_user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_name, password, name, gender, mobile, email, id_card, address', 'required'),
			array('gender', 'numerical', 'integerOnly'=>true),
			array('user_name, password, name, mobile, id_card, postcode', 'length', 'max'=>32),
			array('email', 'length', 'max'=>64),
			array('address', 'length', 'max'=>128),
			array('balance', 'length', 'max'=>12),
			array('gender', 'default', 'value'=>'1'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, user_name, password, name, gender, mobile, email, id_card, address, postcode, balance, regist_time, login_time', 'safe', 'on'=>'search'),
			array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'on'=>'insert', 'message'=>'验证码输入错误！'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'order' => array(self::HAS_ONE, 'Order', 'id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'user_name' => 'User Name',
			'password' => 'Password',
			'name' => 'Name',
			'gender' => 'Gender',
			'mobile' => 'Mobile',
			'email' => 'Email',
			'id_card' => 'Id Card',
			'address' => 'Address',
			'postcode' => 'Postcode',
			'balance' => 'Balance',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('user_name',$this->user_name,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('gender',$this->gender);
		$criteria->compare('mobile',$this->mobile,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('id_card',$this->id_card,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('postcode',$this->postcode,true);
		$criteria->compare('balance',$this->balance,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}